﻿using SmartSpace.Core;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PublishTool
{
    public class PTDbContext : DbContext
    {
        public PTDbContext(string connectionString)
            : base(connectionString)
        {
            Database.SetInitializer<CoreDbContext>(null);
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Module>().ToTable("core_module");
            modelBuilder.Entity<Module>().HasKey(p => p.Id);
            modelBuilder.Entity<Module>().HasMany(p => p.Views)
                .WithRequired(p => p.Module).HasForeignKey(p => p.ModuleId);

            modelBuilder.Entity<ModuleView>().ToTable("core_moduleview");
            modelBuilder.Entity<ModuleView>().HasKey(p => p.Id);

            modelBuilder.Entity<SiteTemplate>().ToTable("core_sitetemplate");
            modelBuilder.Entity<SiteTemplate>().HasKey(p => p.Id);

            base.OnModelCreating(modelBuilder);
        }
    }
}
